package com.qf.dao;

import com.qf.pojo.Admin;
import com.qf.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author 千锋健哥
 */
public class AdminDaoImpl implements AdminDao{

    //1. 创建全局的QueryRunner对象
    private QueryRunner queryRunner = new QueryRunner(DataSourceUtil.getDataSource());

    @Override
    public Admin findAdminByUserName(String username) {
        try {
            String sql = "select * from admin where username=?";
            Admin admin = queryRunner.query(sql, new BeanHandler<Admin>(Admin.class), username);
            return admin;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
